using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WOWEquipOptimizer
{
    /// <summary>
    /// enter conditions and stuff
    /// </summary>
    public partial class ConditionsDialog : Form
    {
        private Dictionary<AttributeName, float> m_Conditions = new Dictionary<AttributeName, float>();

        public Dictionary<AttributeName, float> Conditions
        {
            get { return m_Conditions; }
            set { m_Conditions = value; }
        }
        private void ResetConditions()
        {
            m_Conditions.Clear();
            float value = 0;
            AttributeValueTextBox.Text = value.ToString("N2");
        }
        private void PopulateComboBox()
        {
            AttributeComboBox.Items.Clear();
            AttributeComboBox.Items.AddRange(Enum.GetNames(typeof(AttributeName)));
            AttributeComboBox.Items.Remove(AttributeName.None.ToString());
            AttributeComboBox.Items.Remove(AttributeName.Special.ToString());
            AttributeComboBox.Items.Remove(AttributeName.HasteDirect.ToString());
            AttributeComboBox.Items.Remove(AttributeName.MHWDPS.ToString());
            AttributeComboBox.Items.Remove(AttributeName.MHWS.ToString());
            AttributeComboBox.Items.Remove(AttributeName.OHWDPS.ToString());
            AttributeComboBox.Items.Remove(AttributeName.OHWS.ToString());

        }
        public ConditionsDialog()
        {
            InitializeComponent();
            PopulateComboBox();
            float value = 0;
            AttributeValueTextBox.Text = value.ToString("N2");
        }

        private void SelectedIndexChanged(object sender, EventArgs e)
        {
            string attribute = (string) (sender as ComboBox).SelectedItem;
            AttributeName attrname = AttributeName.None;
            float value = 0;
            try
            {
                 value = float.Parse(AttributeValueTextBox.Text);
                 attrname = (AttributeName)Enum.Parse(typeof(AttributeName), attribute, true);
            }
            catch(Exception)
            {
            }
            if (m_Conditions.ContainsKey(attrname))
            {
                AttributeValueTextBox.Text = m_Conditions[attrname].ToString("N2");
            }
            else
            {
                value = 0;
                AttributeValueTextBox.Text = value.ToString("N2");
            }
        }
        private void ResetButton_Click(object sender, EventArgs e)
        {
            this.ResetConditions();
        }

        private void ValueSetButton_Click(object sender, EventArgs e)
        {
            string attribute = (string)AttributeComboBox.SelectedItem;
            if (attribute == null) return;
            float value = 0;
            if (attribute.Length > 0)
            {
                value = float.Parse(AttributeValueTextBox.Text);
                AttributeName attrname = (AttributeName)Enum.Parse(typeof(AttributeName), attribute, true);
                if (value > 0)
                {
                    if (m_Conditions.ContainsKey(attrname))
                    {
                        m_Conditions[attrname] = value;
                    }
                    else m_Conditions.Add(attrname, value);
                }
                else if (value == 0)
                {
                    if (m_Conditions.ContainsKey(attrname))
                    {
                        m_Conditions.Remove(attrname);
                    }
                }
            }
        }
    }
}